function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

$(function(){


	$(".basic_info").submit(function (e) {
        e.preventDefault()

        var nick_name = $("#nick_name").val();
        var phone = $("#phone").val();
        var mail = $("#mail").val();
        var abstract2=$("#abstract2").val();

        if (!nick_name) {
            alert('请输入店名')
            return
        }

        if (!phone) {
            alert('请输入电话')
            return
        }

        if (!mail) {
            alert('请输入电子邮箱')
            return
        }

        if (!abstract2) {
            abstract2="这个人很懒，什么都没写呢！";
        }

        // TODO 修改用户信息接口
        var params = {
            "nick_name": nick_name,
            "phone": phone,
            "mail": mail,
            "abstract2": abstract2
        }
        
        $.ajax({
            url: "/user_index_basic_info/",
            type: "post",
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            data: JSON.stringify(params),
            success: function (resp) {
                if (resp.errno == "0") {
                    // 更新父窗口内容
                    $('.asdie_name', parent.document).html(params['nick_name'])
                    $('.asdie_abstract', parent.document).html(params['abstract2'])
                }else {
                    alert(resp.errmsg)
                }
            }
        })
        
    })
})